package com.pipayshop.mapper;

import com.pipayshop.domain.StoreCommodityInfo;
import com.pipayshop.domain.dto.StoreCommodityInfoDTO;
import com.pipayshop.domain.vo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * <p>
 * 实体店的商品表 Mapper 接口
 * </p>
 *
 * @author zxb
 * @since 2023-07-27
 */
@Mapper

public interface PhysicalStoreCommodityInfoMapper extends BaseMapper<StoreCommodityInfo> {
    /**
     * 根据用户id查询 用户收藏的商品列表
     *
     * @param userId
     * @return
     */
    List<StoreCommodityInfoVO> selectCollectProductByUserId(@Param("page") Integer page, @Param("limit") Integer limit, @Param("userId") String userId);
    Integer selectAllCollectProductByUserId(@Param("userId") String userId);

    String selectShopIdByCommodityId(@Param("commodityId") String commodityId);
    /**
     * 根据用户id查询用户商品浏览历史
     */
    List<StoreCommodityListVO> selectHistoryProductByUserId(@Param("page") Integer page, @Param("limit") Integer limit, @Param("userId") String userId);
    Integer selectAllHistoryProductByUserId(@Param("userId") String userId);

    /**
     * 根据用户id查询，商品状态查询审核通过和未审核列表
     *
     * @param page
     * @return
     */
    List<StoreCommodityInfoVO> selectCommodityByUidAndStatus (@Param("page") Integer page, @Param("limit") Integer limit,
                                                      @Param("uid") String uid, @Param("status") Integer status);

    /**
     * 根据用户id查询，商品状态查询审核通过和未审核列表的总数
     *
     * @param uid
     * @return
     */
    Integer selectAllCommodity(@Param("uid") String uid, @Param("status") Integer status);

    /**
     * 根据店铺id查询，实体店的商品列表
     *
     * @return
     */
    List<StoreCommodityInfo1VO>selectCommodityByShopId(@Param("shopId") String shopId);

    /**
     * 根据店铺id查询，实体店的商品列表总数
     *
     * @param shopId
     * @return
     */
    Integer selectAllCommodityByShopId(@Param("shopId")String shopId);

    StoreDetailInfoVO selectShopInfoByCommodityId(@Param("commodityId")String commodityId);

    Integer selectCommdityListByShopId(@Param("shopId")String shopId);

    List<ApplicationRecordVO> selectCommdityListByShopIdPage(@Param("shopId")String shopId);

    @Select("select shop_id from store_order_info where order_id = #{orderId}")
    String selectShopIdByOrderId(@Param("orderId")String orderId);

    /**
     * 根据购买数量、商品id
     * @param num
     * @param commodityId
     * @return
     */
    int reduceStock(@Param("num")Integer num,@Param("commodityId")String commodityId);


    /**
     * 根据购买数量、商品id =》商品库存复原
     * @return
     */
    int addStock(@Param("num")Integer num,@Param("commodityId")String commodityId);

    int updateCommodity(StoreCommodityInfoDTO shopCommodityInfoDTO);

    int deleteByCommodityId(String commodityId);
}
